{
  "properties" : { },
  "id" : "7df64cdee2c94cfeb553f67fc5d571a0",
  "script" : null,
  "groupId" : "43baf95fba7a40cebd8be100bec36201",
  "name" : "创建新订单",
  "createTime" : null,
  "updateTime" : 1741367987244,
  "lock" : null,
  "createBy" : null,
  "updateBy" : null,
  "path" : "/new",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\n    \"content\":\"测试正文\",\n    \"package_id\":2\n}",
  "headers" : [ {
    "name" : "token",
    "value" : "993b004d-4d42-4e2e-9001-fbf8c018e7ac",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 200,\n    \"message\": \"success\",\n    \"data\": {\n        \"payUrl\": \"https://zpayz.cn/submit.php?&pid=2024120309443794&type=wxpay&out_trade_no=202503061754348711&notify_url=http://falvpingtai.com/api/payments/callback&return_url=http://falvpingtai.com/arbitrationResult&name=月会员&money=10.00&sign_type=MD5&sign=67796b3e99a3140d43edb5d7a59427fc\",\n        \"id\": 9\n    },\n    \"timestamp\": 1741283674483,\n    \"executeTime\": 361\n}",
  "description" : null,
  "requestBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "content",
      "value" : "测试正文",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "package_id",
      "value" : "2",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "code",
      "value" : "500",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "系统内部出现错误",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "null",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "timestamp",
      "value" : "1733835684748",
      "description" : "",
      "required" : false,
      "dataType" : "Long",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "executeTime",
      "value" : "65",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import log
import cn.hutool.core.util.StrUtil
import cn.dev33.satoken.stp.StpUtil
import cn.hutool.core.date.DateUtil
import cn.hutool.core.util.RandomUtil
import org.ssssssss.magicboot.utils.SignUtils

var userId = StpUtil.getLoginId()
// var userId = 1
log.info("content--->" + body.content::string)
//订单编号
// 生成一个随机数，可以根据需要生成不同位数的随机数
var randomNum = RandomUtil.randomInt(1000, 9999);

// 组合成最终的字符串
var orderNo = DateUtil.format(now(), "yyyyMMddHHmmss") + String.format("%03d", randomNum);
log.info("orderNo--->" + orderNo)

// 根据传上来的套餐id
var packageInfo = db.table("product_package").where().eq("id", body.package_id).selectOne()
if (packageInfo == null) {
    exit 400, "套餐不存在";
}

var packageName = packageInfo.packageName
var money = packageInfo.price::string
var payContent = packageInfo.packageName
//目前也就只能支持微信支付了
var type = "wxpay"

db_res = db.table("orders").insert({
    order_no: orderNo,
    user_id: userId,
    amount: money,
    status: 'pending',
    service_type: packageName,
    payment_method: type,
    transaction_id: '',
    pay_time: '',
    content: payContent,
    product_snapshot:packageInfo::stringify //套餐快照
})
log.info("db_res result-->" + db_res)

//订单编号
var out_trade_no = orderNo
var notify_url = "http://falvpingtai.com/api/payments/callback"
var pid = "2024120309443794"//商户唯一标识
var param = packageName
var return_url = "http://falvpingtai.com/arbitrationResult"
var sign = ""
var sign_type = "MD5"
var key = "pjCxRZKW86DalubQM5iatxH4CwylVD2q"; // 与支付平台签约时获得的密钥

// 组装参数对象
var params = {
    pid: pid,
    type: type,
    out_trade_no: out_trade_no,
    notify_url: notify_url,
    return_url: return_url,
    name: packageName,  //这里要考虑标注开始和结束时间
    money: money,
};
log.info("params-->" + params::string)
var signStr = SignUtils.sign(params, key)
log.info("signStr-->" + signStr)
var signStr2 = SignUtils.sign2(params, key)
log.info("signStr2-->" + signStr2)

params.sign_type = sign_type
params.sign = signStr
// params.param = param


// 1、将发送或接收到的所有参数按照参数名ASCII码从小到大排序（a-z），sign、sign_type、和空值不参与签名！

// 2、将排序后的参数拼接成URL键值对的格式，例如 a=b&c=d&e=f，参数值不要进行url编码。

// 3、再将拼接好的字符串与商户密钥KEY进行MD5加密得出sign签名参数，sign = md5 ( a=b&c=d&e=f + KEY ) （注意：+ 为各语言的拼接符，不是字符！），md5结果为小写。

// 4、具体签名与发起支付的示例代码可下载SDK查看。


// https://zpayz.cn/submit.php?&pid=2024120309443794&type=wxpay&out_trade_no=202412102039428374&notify_url=http://falvpingtai.com/api/payments/callback&return_url=http://falvpingtai.com/arbitrationResult&name=仲裁书生成&money=29.9&sign_type=MD5&sign=8402e8b9588f586464e512d19cb81f33&param=仲裁书生成

// https://zpayz.cn/submit.php?name=iphone xs Max 一台&money=0.03&out_trade_no=201911914837526544601&notify_url=http://www.aaa.com/notify_url.php&pid=201901151314084206659771&param=金色 256G&return_url=http://www.baidu.com&sign=28f9583617d9caf66834292b6ab1cc89&sign_type=MD5&type=alipay



var resultUrl = "https://zpayz.cn/submit.php?";

for (k, v in params) {
    resultUrl += (resultUrl ? '&' : '') + k + '=' + params[k];
    // if (k !== 'sign') {
    //     resultUrl += (resultUrl ? '&' : '') + k + '=' + params[k];
    // }
}
log.info("resultUrl-->" + resultUrl)

return {
    payUrl:resultUrl,
    id:db_res
}